//
//  BBViewThumbnailer.m
//  xNose
//
//  Created by ben smith on 9/10/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "BBViewThumbnailer.h"


@implementation BBViewThumbnailer

// this creates an image from the entire 'visible' rectangle of a view
// for offscreen views this is the entire view
+ (NSImage *)createImageFromView:(NSView *)view {
	NSRect rect = [view bounds];
	return [BBViewThumbnailer createImageFromSubView:view rect:rect];
}

// this creates an image from a subset of the view's visible rectangle
+ (NSImage *)createImageFromSubView:(NSView *)view rect:(NSRect)rect{
	// first get teh properly setup bitmap for this view
	NSBitmapImageRep *imageRep = [view bitmapImageRepForCachingDisplayInRect:rect];
	// now use that bitmap to store the desired view rectangle as bits
	[view cacheDisplayInRect:rect toBitmapImageRep:imageRep];
	// jam that bitrep into an image and return it
	NSImage *image = [[[NSImage alloc] initWithSize:rect.size] autorelease];
	[image addRepresentation:imageRep];
	return image;
}


@end
